<?php

namespace App\Models\Factory\V2;


use App\Helpers\RestResponseFactory;
use App\Helpers\Utils;
use App\Models\AbsModelFactory;
use App\Models\Orm\Activity;
use App\Models\Orm\AwUserIdentityverify;
use App\Models\Orm\AwUserIntegral;
use App\Models\Orm\User;


/**
 * @file AwUserIntegralFactory.php
 * @brief 用户积分工厂
 * @author 
 * @version 2.*
 * @date 2017-11-25
 */
class AwUserIntegralFactory extends AbsModelFactory
{

    /**
     * 初始化积分表
     * @param $identity
     * @param $labels
     * @param $amount
     * @return \Illuminate\Database\Eloquent\Collection|static[]
     */
    public static function initIntegral($user_id)
    {
        $data['user_id'] = $user_id;
       $result =  AwUserIntegral::firstOrCreate($data);
        return $result ? true : false;
    }

    //查看用户完成资料是否已经加积分
    public static  function checkIdentityVerfity($user_id)
    {
        $result = AwUserIdentityverify::where('user_id',$user_id)->first();

        return $result ? false : true;
    }


    //插入用户完成资料加积分流水表
    public static function createIdentityVerfity($user_id)
    {
        // 生成提现记录
        $insert_data = [
            'user_id' => $user_id,
            'integral' => AwUserIdentityverify::INTEGRAL_IDENTITY,
            'status' =>AwUserIdentityverify::STATUS_INIT,
            'ip' => strval(ip2long(Utils::ipAddress())),
        ];

        $order_id = AwUserIdentityverify::insertGetId($insert_data);

        return $order_id ? $order_id : false;
    }

}
